/**
 * Copyright (c) 2020-2024, huli.com
 * All rights reserved.
 */
package com.xiaohujr.xuexue.cpu;

/**
 * @author Xue Xue (xuexue1@huli.com)
 * @version 1.0
 * @since 2020/5/11
 */
public class CacheTest {
    private static void cachelineTest() {
        int arr[][] = new int[10000][10000];
        long timestamp = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            for (int j = 0; j < 1000; j++) {
                arr[i][j] = 0;
            }
        }
        System.out.println(System.currentTimeMillis() - timestamp);

    }

    private static void cachelineTest2() {
        int arr[][] = new int[10000][10000];
        long timestamp = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            for (int j = 0; j < 1000; j++) {
                arr[j][i] = 0;
            }
        }
        System.out.println(System.currentTimeMillis() - timestamp);

    }


    public static void main(String[] args) {
        cachelineTest();
        cachelineTest2();
    }
}
